package com.vint.lintcode;

import com.vint.common.TreeNode;

/**
 * 寻找树中最大的节点
 */
public class Lintcode632 {
	public TreeNode maxNode(TreeNode root) {
		if(null==root)
			return root;
		if(root.left==null && root.right == null)return root;
		TreeNode left = maxNode(root.left);
		TreeNode right = maxNode(root.right);
		if(left == null) {
			if(right.val > root.val){
				return right;
			}else {
				return root;
			}
		}
		if(right==null){
			if(left.val > root.val){
				return left;
			}else {
				return root;
			}
		}
		if(root.val >= left.val && root.val >= right.val) return root;
		if(left.val >= root.val && left.val >= right.val) return left;
		if(right.val >= left.val && right.val >= root.val) return right;

		return root;
	}
	public static void main(String[] args) {
	}
}
